package com.example.springboot.common.vo;

import com.example.springboot.entity.SysMenu;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PermissionsMenu {

	public String title;
	public String href;
	public String icon;
	public String target;
	public List<PermissionsMenu> child;

	public static List<PermissionsMenu> TreeBuild(List<SysMenu> menuList, Long id) {

		List<PermissionsMenu> treeMenuList = new ArrayList<>();

		List<SysMenu> menuList1 = new ArrayList<>();

		for (SysMenu menu : menuList) {
			if (menu.getParentid() == id) {
				menuList1.add(menu);
			} else {
				continue;
			}
		}

		for (SysMenu menu : menuList1) {
			if (!menu.getMenutype().equals("2")) {
				PermissionsMenu treeMenu = new PermissionsMenu();
				treeMenu.setTitle(menu.getName());
				treeMenu.setHref(menu.getAppurl());
				treeMenu.setIcon(menu.getImgurl());
				treeMenu.setTarget("_self");
				treeMenu.setChild(TreeBuild(menuList, menu.getId()));
				treeMenuList.add(treeMenu);
			}

		}
		return treeMenuList;
	}
}
